﻿/// <reference path="../../../EditedVersion/SinglePageApp/libs/mongoLab.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/libs/protoClass.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/libs/jquery-2.0.2.min.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/libs/jquery-ui/ui/jquery-ui.js
/// <reference path="../../../EditedVersion/SinglePageApp/libs/knockout-2.2.1.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/scripts/TripDetails.js" />
/// <reference path="../../../EditedVersion/SinglePageApp/scripts/dbModule.js" />

describe("Db module", function () {
    describe("Get", function () {
        it("all entries from db", function () {
            var get = new dbModule.Get();
            var tripFrom = 'Plovdiv';
            var tripTo = 'Pleven';
            var tripDateOfDeparture = "19/06/2010";
            var trip = new TripDetails.Trip(tripFrom, tripTo, tripDateOfDeparture);
            get.offerByConditions(trip, function (data) {
                var allOffers = [];
                for (var i = 0; i < data.length; i++) {
                    var obj = new TripDetails.Offer(data[i].driver, data[i].price, data[i].trip);
                    JSON.stringify(obj);
                    allOffers.push(obj);
                    allOffers.sort();
                }

                expect(allOffers.length).toBe(17);
            });
        });
    });

    describe("Set", function () {
        it("an entry to db", function () {
            var put = new dbModule.Put(offer);
            var bmw = new TripDetails.Vehicle("Автомобил", "Bmw", 2002, 4, 7);
            var driver = new TripDetails.Driver("Ивелин", "Соколов", "asokolov@gmail.com", "0888392239", 27, "Мъж", bmw, undefined, undefined);
            var offer = new TripDetails.Offer(
                driver,
                new TripDetails.Price(22, "Lv."),
                new TripDetails.Trip("София", "Варна", "07/12/2013"));
            var put = new dbModule.Put(offer);
        });
    });
});